#include"tree.h"
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<time.h>

int main(int argc,char * argv[]){

    TreeNode * root = NULL;
    int num = 0;
    int iter = 0;
    unsigned int seed = time(NULL);

    if(argc >= 2){

        num = (int)strtol(argv[1],NULL,10);
    }
    if(num < 8) num = 8;

    int * array = malloc(sizeof(int) * num);
    if(NULL == array){

        return EXIT_FAILURE;
    }
    for(int i = 0;i < num;++i){

        array[i] = rand() % 10000;
    }
    for(iter = 0;iter < num;iter++){

        int val = array[iter];
        printf("insert %d.\n",val);
        root = Tree_insert(root,val);
        Tree_print(root);
    }
    for(iter = 0;iter < num;iter++){

        int index = rand() % (2 * num);
        if(index < num){

            int val = array[index];
            printf("delete %d.\n",val);
            root = Tree_delete(root,val);
            Tree_print(root);
        }
    }
    Tree_destroy(root);
    free(array);
    return EXIT_SUCCESS;
}